package com.mock.water.core.aop;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

import java.lang.reflect.Method;

/**
 * 自定义方法拦截器
 * @Author ifredomvip@gmail.com
 * @Date 2023/3/31 0:58
 */
public class CustomMethodInterceptor implements MethodInterceptor {

    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
        System.out.println("invoke method before");

        Object arg = invocation.getArguments()[0];
        System.out.println("arg " + arg);

        Object ti = invocation.getThis();
        System.out.println("this " + ti);

        Method method = invocation.getMethod();
        System.out.println("method " + method);

        System.out.println("toString " + toString());

        Object result = invocation.proceed();
        System.out.println("invoke method after");
        return result;
    }

}